'use strict';

module.exports = function(grunt) {

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        watch: {
            options: {
                debounceDelay: 250
            },
            css: {
                files: 'devDependencies/css/**/*.css',
                tasks: 'newer:cssmin:css'
            },
            img: {
                files: 'devDependencies/**/*.{png,jpg,jpeg,gif}',
                tasks: 'newer:copy:img'
            },
            js: {
                files: 'devDependencies/scripts/**/*.js',
                tasks: 'newer:uglify:js'
            }
        },
        cssmin: {
            css: {
                options: {
                    sourceMap: true
                },
                files: [{
                    expand: true,
                    cwd: 'devDependencies/css/',
                    src: '**/*.css',
                    dest: 'dist/css/'
                }]
            },
            buildcss: {
                files: [{
                    expand: true,
                    cwd: 'devDependencies/css/',
                    src: '**/*.css',
                    dest: 'dist/css/'
                }]
            }
        },
        uglify: {
            js: {
                options: {
                    sourceMap: true
                },
                files: [{
                    expand: true,
                    cwd: 'devDependencies/scripts',
                    src: '**/*.js',
                    dest: 'dist/scripts/'
                }]
            },
            buildjs: {
                files: [{
                    expand: true,
                    cwd: 'devDependencies/scripts',
                    src: '**/*.js',
                    dest: 'dist/scripts/'
                }]
            }
        },
        copy: {
            img: {
                files: [{
                    expand: true,
                    cwd: 'devDependencies',
                    src: '**/*.{png,jpg,jpeg,gif}',
                    dest: 'dist/'
                }]
            }
        },
        clean: {
            build: {
                src: ['dist/css/**/*.css', 'dist/css/**/*.map', 'dist/scripts/**/*.js', 'dist/scripts/**/*.map', 'dist/images/**/*.{png,jpg,jpeg,gif}', 'dist/css/**/*.{png,jpg,jpeg,gif}']
            }
        }
    });

    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-newer');

    grunt.registerTask('default', ['clean:build', 'cssmin:css', 'uglify:js', 'copy:img', 'watch']);

    // grunt.registerTask('default', function(){
    //     grunt.task.run("cssmin:css:sourceMap")
    // });

    grunt.registerTask('build', ['clean:build', 'cssmin:buildcss', 'uglify:buildjs', 'copy:img']);
}
